﻿using Framework;
using UnityEngine;
using UnityEngine.UI;

namespace PokerGame
{
    public class SettingPanel : UIBase
    {

        private Button btnSet;
        private Image imgBg;
        private Button btnClose;
        private Text txtAudio;
        private Toggle tglAudio;
        private Text txtVolume;
        private Slider sldVolume;
        private Button btnQuit;

        #region runtime
        private void Awake()
        {
            Bind();
            btnSet = transform.Find("btnSet").GetComponent<Button>();
            imgBg = transform.Find("imgBg").GetComponent<Image>();
            btnClose = transform.Find("btnClose").GetComponent<Button>();
            txtAudio = transform.Find("txtAudio").GetComponent<Text>();
            tglAudio = transform.Find("tglAudio").GetComponent<Toggle>();
            txtVolume = transform.Find("txtVolume").GetComponent<Text>();
            sldVolume = transform.Find("sldVolume").GetComponent<Slider>();
            btnQuit = transform.Find("btnQuit").GetComponent<Button>();
        }

        private void Start()
        {
            SetSettingUIActive(false);
            btnSet.onClick.AddListener(BtnSet_OnClick);
            btnClose.onClick.AddListener(BtnClose_OnClick);
            tglAudio.onValueChanged.AddListener(TglAudio_OnValueChanged);
            sldVolume.onValueChanged.AddListener(SldVolume_OnValueChanged);
            btnQuit.onClick.AddListener(BtnQuit_OnClick);
        }
        private void OnDestroy()
        {
            btnSet.onClick.RemoveListener(BtnSet_OnClick);
            btnClose.onClick.RemoveListener(BtnClose_OnClick);
            tglAudio.onValueChanged.RemoveListener(TglAudio_OnValueChanged);
            sldVolume.onValueChanged.RemoveListener(SldVolume_OnValueChanged);
            btnQuit.onClick.RemoveListener(BtnQuit_OnClick);
        }
        #endregion

        public override void Execute(int eventCode, object message)
        {
            switch (eventCode)
            {
                default:
                    break;
            }
        }

        #region private method
        private void BtnSet_OnClick()
        {
            SetSettingUIActive(true);
        }
        private void BtnClose_OnClick()
        {
            SetSettingUIActive(false);
        }
        private void BtnQuit_OnClick()
        {
            Application.Quit();
        }

        private void TglAudio_OnValueChanged(bool value)
        {
            //TODO: 开闭声音
        }
        private void SldVolume_OnValueChanged(float value)
        {
            //TODO: 音量大小
        }

        private void SetSettingUIActive(bool active)
        {
            imgBg.gameObject.SetActive(active);
            btnClose.gameObject.SetActive(active);
            txtAudio.gameObject.SetActive(active);
            tglAudio.gameObject.SetActive(active);
            txtVolume.gameObject.SetActive(active);
            sldVolume.gameObject.SetActive(active);
            btnQuit.gameObject.SetActive(active);
        }
        #endregion
    }
}
